//: [Previous](@previous)
/*:
 
 #9 [Palindrome Number](https://leetcode.com/problems/palindrome-number/description/)
 
 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
 
 判断一个整数是否是回文数。从前往后和从后往前是一样的。
 
 Example 1:
 ```
 Input: 121
 Output: true
 ```
 
 Example 2:
 ```
 Input: -121
 Output: false
 Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
 ```
 
 Example 3:
 ```
 Input: 10
 Output: false
 Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
 ```
 
 **Follow up:**
 
 Coud you solve it without converting the integer to a string?
 
 不将整数转成字符串去解决？
 
 */
import Foundation

class Solution {
    func isPalindrome(_ x: Int) -> Bool {
        if x < 0 {
            return false
        }
        
        var num = x
        var result = 0
        
        while num != 0 {
            result = result * 10 + num % 10
            num = num / 10
        }
        
        if result == x {
            return true
        }
        
        return false
    }
}

print(Solution().isPalindrome(121))
print(Solution().isPalindrome(10))
print(Solution().isPalindrome(-121))


//: [Next](@next)
